

***** Step 2: Prepare main Gasoil data ****


clear
use "$path\Intermediary Data\Prix_Gazole30_Level_DailyFULL.dta", clear

******
drop id_pdv_30num
gen id_pdv=substr(id_pdv_30,1,8)
replace id_pdv=subinstr(id_pdv, "_", "",.)

destring id_pdv, replace force
capture drop autoroute classif_num
merge m:1 id_pdv using "$path\Intermediary Data\data_PDV_autoroutes_supermarches_v3.dta" 
drop _merge



capture drop delta_lprix
capture drop delta_lprix_ht
capture drop inflation_ttc
capture drop inflation_ht

bysort id_pdv_30 (date_maj_num): gen delta_lprix=log(prix)-log(prix[_n-1])
bysort id_pdv_30 (date_maj_num): gen delta_lprix_ht=log(prix_ht)-log(prix_ht[_n-1])


replace delta_lprix=. if delta_lprix<-.0396419 | delta_lprix>.0408567
replace delta_lprix_ht=. if delta_lprix_ht<-.0788907 | delta_lprix_ht>.0736579



merge m:m date_maj_num using "$path\Intermediary Data\DataReg_RotterdamBrent"


bysort id_pdv_30 (date_maj_num): replace diesel_rotterdam_euro=diesel_rotterdam_euro[_n-1] if diesel_rotterdam_euro==.
bysort id_pdv_30 (date_maj_num): replace diesel_rotterdam=diesel_rotterdam[_n-1] if diesel_rotterdam==.
drop _m

egen id=group(id_pdv_30)



gen j=int((date_maj_num - 17169)/7)
gen j2=int((date_maj_num - 17169+1))
gen j3=j2-j*7
drop j2



drop if j3<1
drop date_tokeep delta_lprix
drop  gasoline_rotterdam  id_pdv_30



save "$path\Intermediary Data\DataReg_Gasoil.dta", replace
